#!/usr/bin/env Rscript
##################################
############ Preamble ############
##################################
# set language to English
Sys.setenv(LANG = "en")

# clean up
rm(list = ls())

# Set working directory: Please set your own
if (Sys.getenv("RSTUDIO") == "1") setwd("~/Dropbox/cues_bjps_replication")

library(Rmisc)
library(tidyverse)
library(readxl)
library(stargazer)
library(kableExtra)
library(sandwich)
library(broom)
library(dotwhisker)
library(jtools)
library(scales)



# read data
raw_data <- read_xlsx("data/final_survey_data.xlsx")
raw_data <- raw_data %>%
  dplyr::rename(
    number = lfdn,
    completion_time = duration,
    disposition_code = dispcode,
    treatment = c_0031,
    cover_page = v_27,
    age = v_28,
    age_range = v_29,
    gender = v_30,
    state = v_31,
    born_in_germany = v_39,
    sign_petition_self = v_47,
    sensitive_item_agree = dupl1_v_44,
    left_right = dupl1_v_41,
    petition_appropriate_self = v_48,
    sign_petition_others = v_49,
    petition_appropriate_others = v_50,
    delete_tweet = v_51,
    voted_2021 = v_53,
    party_voted_2021 = v_54,
    party_voted_2021_other_which = v_55,
    voted_2017 = v_56,
    party_voted_2017 = v_57,
    party_voted_2017_other_which = v_58,
    household_income = v_59,
    education = v_60,
    mother_born_where = v_61,
    mother_born_other_where = v_62,
    father_born_where = v_63,
    father_born_other_where = v_64
  )

raw_data <- raw_data %>%
  mutate(treatment = replace(treatment, which(treatment == 1), "Mainstream Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 2), "Mainstream Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 3), "RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 4), "RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 5), "Mainstream and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 6), "Mainstream and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 7), "Mainstream Disapprove and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 8), "Mainstream Disapprove and RRP Approve")) %>%
  mutate(treatment = replace(treatment, which(treatment == 9), "Control")) %>%
  mutate(treatment = replace(treatment, which(treatment == 10), "Control"))

# recode state names
raw_data <- raw_data %>%
  mutate(state = replace(state, which(state == 1), "Baden-Wuerttemberg")) %>%
  mutate(state = replace(state, which(state == 2), "Bayern")) %>%
  mutate(state = replace(state, which(state == 3), "Berlin")) %>%
  mutate(state = replace(state, which(state == 4), "Brandenburg")) %>%
  mutate(state = replace(state, which(state == 5), "Bremen")) %>%
  mutate(state = replace(state, which(state == 6), "Hamburg")) %>%
  mutate(state = replace(state, which(state == 7), "Hessen")) %>%
  mutate(state = replace(state, which(state == 8), "Mecklenburg-Vorpommern")) %>%
  mutate(state = replace(state, which(state == 9), "Niedersachsen")) %>%
  mutate(state = replace(state, which(state == 10), "Nordrhein-Westfalen")) %>%
  mutate(state = replace(state, which(state == 11), "Rheinland-Pfalz")) %>%
  mutate(state = replace(state, which(state == 12), "Saarland")) %>%
  mutate(state = replace(state, which(state == 13), "Sachsen")) %>%
  mutate(state = replace(state, which(state == 14), "Sachsen-Anhalt")) %>%
  mutate(state = replace(state, which(state == 15), "Schleswig-Holstein")) %>%
  mutate(state = replace(state, which(state == 16), "Thueringen"))

# recode age_ranges
raw_data <- raw_data %>%
  mutate(age_range = replace(age_range, which(age_range == 1), "18 - 29 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 2), "30 - 39 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 3), "40 - 49 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 4), "50 - 59 years")) %>%
  mutate(age_range = replace(age_range, which(age_range == 5), "60 - 90 years"))

# recode education
raw_data <- raw_data %>%
  mutate(education = replace(education, which(education == 1), "Still schooling")) %>%
  mutate(education = replace(education, which(education == 2), "Elementary school diploma")) %>%
  mutate(education = replace(education, which(education == 3), "Secondary school leaving certificate")) %>%
  mutate(education = replace(education, which(education == 4), "Advanced technical college entrance qualification")) %>%
  mutate(education = replace(education, which(education == 5), "Subject-related higher education entrance qualification")) %>%
  mutate(education = replace(education, which(education == 6), "Fachhochschulabschluss")) %>%
  mutate(education = replace(education, which(education == 7), "Hochschulabschluss")) %>%
  mutate(education = replace(education, which(education == 8), "Promotion")) %>%
  mutate(education = replace(education, which(education == 9), "No school leaving certificate"))

# recode gender
raw_data <- raw_data %>%
  mutate(gender = replace(gender, which(gender == 1), "Male")) %>%
  mutate(gender = replace(gender, which(gender == 2), "Female"))

# recode sensitive item - change sensitive item response "disagree" to 0
raw_data <- raw_data %>%
  mutate(sensitive_item_agree = replace(sensitive_item_agree, which(sensitive_item_agree == 2), 0))

# recode coordination game - change "not willing to sign" from 2 to 0
raw_data <- raw_data %>%
  mutate(sign_petition_self = replace(sign_petition_self, which(sign_petition_self == 2), 0))

# recode punishment exp - change "do not delete tweet" from 2 to 0
raw_data <- raw_data %>%
  mutate(delete_tweet = replace(delete_tweet, which(delete_tweet == 2), 0))

# recode left_right 100 is 0, 99 is NA
raw_data <- raw_data %>%
  mutate(left_right = replace(left_right, which(left_right == 100), 0)) %>%
  mutate(left_right = replace(left_right, which(left_right == 99), NA))

raw_data <- raw_data %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 1), "CDU/CSU")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 2), "SPD")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 3), "AfD")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 4), "Green")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 5), "FDP")) %>%
  mutate(party_voted_2021 = replace(party_voted_2021, which(party_voted_2021 == 6), "Die Linke"))

# remove incompletes or inattentives
analysis_data <- raw_data %>%
  filter(disposition_code == "31" | disposition_code == "32")

# clean up sensitive item - drop -77s, merge both columns
analysis_data <- analysis_data %>%
  mutate(sensitive_item_agree = replace(sensitive_item_agree, which(sensitive_item_agree < 0), NA))

# Create dummy variable
analysis_data$MRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream Approve", 1, 0)
analysis_data$RRPapprovedummy <- ifelse(analysis_data$treatment == "RRP Approve", 1, 0)
analysis_data$MRPapproveRRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream and RRP Approve", 1, 0)
analysis_data$MRPdisapproveRRPapprovedummy <- ifelse(analysis_data$treatment == "Mainstream Disapprove and RRP Approve", 1, 0)



# cleaning - Elementary and Secondary School

# subset analysis data
analysis_data_elementaryandsecondaryschool <- analysis_data %>%
  filter(education == "Elementary school diploma" | education == "Secondary school leaving certificate")

# mainstream only
mainstream_only_elementaryandsecondaryschool <- analysis_data_elementaryandsecondaryschool %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only_elementaryandsecondaryschool <- analysis_data_elementaryandsecondaryschool %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only_elementaryandsecondaryschool <- analysis_data_elementaryandsecondaryschool %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only_elementaryandsecondaryschool <- analysis_data_elementaryandsecondaryschool %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data_elementaryandsecondaryschool[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data_elementaryandsecondaryschool[, c(18, 19, 20, 21, 22, 23)])
left_only_elementaryandsecondaryschool[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only_elementaryandsecondaryschool[, c(18, 19, 20, 21, 22, 23)])
right_only_elementaryandsecondaryschool[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only_elementaryandsecondaryschool[, c(18, 19, 20, 21, 22, 23)])
# rrp_only_elementaryandsecondaryschool[,c(18,19,20,21,22,23)]<-scale(rrp_only_elementaryandsecondaryschool[,c(18,19,20,21,22,23)])


# Sensitive Item -  Elementary and Secondary School

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_elementaryandsecondaryschool <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_elementaryandsecondaryschool)
sensitive_item_controls_leftonly_elementaryandsecondaryschool <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_elementaryandsecondaryschool)
sensitive_item_controls_rightonly_elementaryandsecondaryschool <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_elementaryandsecondaryschool)
# sensitive_item_controls_rrponly_elementaryandsecondaryschool <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_elementaryandsecondaryschool)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_elementaryandsecondaryschool <- summ(sensitive_item_controls_fullsample_elementaryandsecondaryschool, robust = "HC1")
robust_sensitive_item_controls_leftonly_elementaryandsecondaryschool <- summ(sensitive_item_controls_leftonly_elementaryandsecondaryschool, robust = "HC1")
robust_sensitive_item_controls_rightonly_elementaryandsecondaryschool <- summ(sensitive_item_controls_rightonly_elementaryandsecondaryschool, robust = "HC1")
# robust_sensitive_item_controls_rrponly_elementaryandsecondaryschool <- summ(sensitive_item_controls_rrponly_elementaryandsecondaryschool, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_elementaryandsecondaryschool_df <- broom::tidy(robust_sensitive_item_controls_fullsample_elementaryandsecondaryschool) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_elementaryandsecondaryschool_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_elementaryandsecondaryschool_df <- broom::tidy(robust_sensitive_item_controls_leftonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_elementaryandsecondaryschool_df)[7] <- "term"

robust_sensitive_item_controls_rightonly_elementaryandsecondaryschool_df <- broom::tidy(robust_sensitive_item_controls_rightonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_elementaryandsecondaryschool_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_elementaryandsecondaryschool_df <- broom::tidy(robust_sensitive_item_controls_rrponly_elementaryandsecondaryschool) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_elementaryandsecondaryschool_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_elementaryandsecondaryschool_df)[7] <- "term"


# Willingness to Sign Petition - elementaryandsecondaryschool only


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_elementaryandsecondaryschool <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_elementaryandsecondaryschool)
sign_petition_self_controls_leftonly_elementaryandsecondaryschool <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_elementaryandsecondaryschool)
sign_petition_self_controls_rightonly_elementaryandsecondaryschool <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_elementaryandsecondaryschool)
# sign_petition_self_controls_rrponly_elementaryandsecondaryschool <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_elementaryandsecondaryschool)

# robust SEs
robust_sign_petition_self_controls_fullsample_elementaryandsecondaryschool <- summ(sign_petition_self_controls_fullsample_elementaryandsecondaryschool, robust = "HC1")
robust_sign_petition_self_controls_leftonly_elementaryandsecondaryschool <- summ(sign_petition_self_controls_leftonly_elementaryandsecondaryschool, robust = "HC1")
robust_sign_petition_self_controls_rightonly_elementaryandsecondaryschool <- summ(sign_petition_self_controls_rightonly_elementaryandsecondaryschool, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_elementaryandsecondaryschool <- summ(sign_petition_self_controls_rrponly_elementaryandsecondaryschool, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_elementaryandsecondaryschool) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_elementaryandsecondaryschool_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_elementaryandsecondaryschool_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_elementaryandsecondaryschool_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_elementaryandsecondaryschool) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_elementaryandsecondaryschool_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_elementaryandsecondaryschool_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - elementaryandsecondaryschool only

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_elementaryandsecondaryschool)
petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_elementaryandsecondaryschool)
petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_elementaryandsecondaryschool)
# petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_elementaryandsecondaryschool)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool <- summ(petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool <- summ(petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool <- summ(petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool <- summ(petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool_df)[7] <- "term"



# Empirical Expectations - elementaryandsecondaryschool only

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_elementaryandsecondaryschool <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_elementaryandsecondaryschool)
sign_petition_others_controls_leftonly_elementaryandsecondaryschool <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_elementaryandsecondaryschool)
sign_petition_others_controls_rightonly_elementaryandsecondaryschool <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_elementaryandsecondaryschool)
# sign_petition_others_controls_rrponly_elementaryandsecondaryschool <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_elementaryandsecondaryschool)

# robust SEs
robust_sign_petition_others_controls_fullsample_elementaryandsecondaryschool <- summ(sign_petition_others_controls_fullsample_elementaryandsecondaryschool, robust = "HC1")
robust_sign_petition_others_controls_leftonly_elementaryandsecondaryschool <- summ(sign_petition_others_controls_leftonly_elementaryandsecondaryschool, robust = "HC1")
robust_sign_petition_others_controls_rightonly_elementaryandsecondaryschool <- summ(sign_petition_others_controls_rightonly_elementaryandsecondaryschool, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_elementaryandsecondaryschool <- summ(sign_petition_others_controls_rrponly_elementaryandsecondaryschool, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_elementaryandsecondaryschool) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_elementaryandsecondaryschool_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_elementaryandsecondaryschool_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_elementaryandsecondaryschool_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_elementaryandsecondaryschool_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_elementaryandsecondaryschool) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_elementaryandsecondaryschool_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_elementaryandsecondaryschool_df)[7] <- "term"



# Normative Expectations - elementaryandsecondaryschool only

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_elementaryandsecondaryschool)
petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_elementaryandsecondaryschool)
petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_elementaryandsecondaryschool)
# petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_elementaryandsecondaryschool)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool <- summ(petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool <- summ(petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool <- summ(petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool <- summ(petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool_df)[7] <- "term"



# Sanctioning - elementaryandsecondaryschool only

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_elementaryandsecondaryschool <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_elementaryandsecondaryschool)
delete_tweet_controls_leftonly_elementaryandsecondaryschool <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_elementaryandsecondaryschool)
delete_tweet_controls_rightonly_elementaryandsecondaryschool <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_elementaryandsecondaryschool)
# delete_tweet_controls_rrponly_elementaryandsecondaryschool <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_elementaryandsecondaryschool)

# robust SEs
robust_delete_tweet_controls_fullsample_elementaryandsecondaryschool <- summ(delete_tweet_controls_fullsample_elementaryandsecondaryschool, robust = "HC1")
robust_delete_tweet_controls_leftonly_elementaryandsecondaryschool <- summ(delete_tweet_controls_leftonly_elementaryandsecondaryschool, robust = "HC1")
robust_delete_tweet_controls_rightonly_elementaryandsecondaryschool <- summ(delete_tweet_controls_rightonly_elementaryandsecondaryschool, robust = "HC1")
# robust_delete_tweet_controls_rrponly_elementaryandsecondaryschool <- summ(delete_tweet_controls_rrponly_elementaryandsecondaryschool, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_elementaryandsecondaryschool_df <- broom::tidy(robust_delete_tweet_controls_fullsample_elementaryandsecondaryschool) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_elementaryandsecondaryschool_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_elementaryandsecondaryschool_df <- broom::tidy(robust_delete_tweet_controls_leftonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_elementaryandsecondaryschool_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_elementaryandsecondaryschool_df <- broom::tidy(robust_delete_tweet_controls_rightonly_elementaryandsecondaryschool) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_elementaryandsecondaryschool_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_elementaryandsecondaryschool_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_elementaryandsecondaryschool_df <- broom::tidy(robust_delete_tweet_controls_rrponly_elementaryandsecondaryschool) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_elementaryandsecondaryschool_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_elementaryandsecondaryschool_df)[7] <- "term"

# final joining of all the models
joined_models_controls_elementaryandsecondaryschool <- rbind(
  robust_sign_petition_self_controls_fullsample_elementaryandsecondaryschool_df,
  robust_sign_petition_self_controls_leftonly_elementaryandsecondaryschool_df,
  robust_sign_petition_self_controls_rightonly_elementaryandsecondaryschool_df,
  # robust_sign_petition_self_controls_rrponly_elementaryandsecondaryschool_df,
  robust_sensitive_item_controls_fullsample_elementaryandsecondaryschool_df,
  robust_sensitive_item_controls_leftonly_elementaryandsecondaryschool_df,
  robust_sensitive_item_controls_rightonly_elementaryandsecondaryschool_df,
  # robust_sensitive_item_controls_rrponly_elementaryandsecondaryschool_df,
  robust_petition_appropriate_self_controls_fullsample_elementaryandsecondaryschool_df,
  robust_petition_appropriate_self_controls_leftonly_elementaryandsecondaryschool_df,
  robust_petition_appropriate_self_controls_rightonly_elementaryandsecondaryschool_df,
  # robust_petition_appropriate_self_controls_rrponly_elementaryandsecondaryschool_df,
  robust_sign_petition_others_controls_fullsample_elementaryandsecondaryschool_df,
  robust_sign_petition_others_controls_leftonly_elementaryandsecondaryschool_df,
  robust_sign_petition_others_controls_rightonly_elementaryandsecondaryschool_df,
  # robust_sign_petition_others_controls_rrponly_elementaryandsecondaryschool_df,
  robust_petition_appropriate_others_controls_fullsample_elementaryandsecondaryschool_df,
  robust_petition_appropriate_others_controls_leftonly_elementaryandsecondaryschool_df,
  robust_petition_appropriate_others_controls_rightonly_elementaryandsecondaryschool_df,
  # robust_petition_appropriate_others_controls_rrponly_elementaryandsecondaryschool_df,
  robust_delete_tweet_controls_fullsample_elementaryandsecondaryschool_df,
  robust_delete_tweet_controls_leftonly_elementaryandsecondaryschool_df,
  robust_delete_tweet_controls_rightonly_elementaryandsecondaryschool_df
  # robust_delete_tweet_controls_rrponly_elementaryandsecondaryschool_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_elementaryandsecondaryschool$sample <- factor(joined_models_controls_elementaryandsecondaryschool$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e9 <- dwplot(joined_models_controls_elementaryandsecondaryschool,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Elementary and Secondary School: Treatment Conditions against Control Condition (With Controls)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e9.png", plot = fig_e9,
  width = 15, height = 10
)

# cleaning - Secondary School and Higher Ed Entrance Exam

# subset analysis data
analysis_data_secondaryandhigheredentrance <- analysis_data %>%
  filter(education == "Advanced technical college entrance qualification" | education == "Secondary school leaving certificate" | education == "Subject-related higher education entrance qualification")

# mainstream only
mainstream_only_secondaryandhigheredentrance <- analysis_data_secondaryandhigheredentrance %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only_secondaryandhigheredentrance <- analysis_data_secondaryandhigheredentrance %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only_secondaryandhigheredentrance <- analysis_data_secondaryandhigheredentrance %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only_secondaryandhigheredentrance <- analysis_data_secondaryandhigheredentrance %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data_secondaryandhigheredentrance[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data_secondaryandhigheredentrance[, c(18, 19, 20, 21, 22, 23)])
left_only_secondaryandhigheredentrance[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only_secondaryandhigheredentrance[, c(18, 19, 20, 21, 22, 23)])
right_only_secondaryandhigheredentrance[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only_secondaryandhigheredentrance[, c(18, 19, 20, 21, 22, 23)])
# rrp_only_secondaryandhigheredentrance[,c(18,19,20,21,22,23)]<-scale(rrp_only_secondaryandhigheredentrance[,c(18,19,20,21,22,23)])


# Sensitive Item -  Secondary School and Higher Ed Entrance Exam

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_secondaryandhigheredentrance <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_secondaryandhigheredentrance)
sensitive_item_controls_leftonly_secondaryandhigheredentrance <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_secondaryandhigheredentrance)
sensitive_item_controls_rightonly_secondaryandhigheredentrance <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_secondaryandhigheredentrance)
# sensitive_item_controls_rrponly_secondaryandhigheredentrance <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_secondaryandhigheredentrance)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_secondaryandhigheredentrance <- summ(sensitive_item_controls_fullsample_secondaryandhigheredentrance, robust = "HC1")
robust_sensitive_item_controls_leftonly_secondaryandhigheredentrance <- summ(sensitive_item_controls_leftonly_secondaryandhigheredentrance, robust = "HC1")
robust_sensitive_item_controls_rightonly_secondaryandhigheredentrance <- summ(sensitive_item_controls_rightonly_secondaryandhigheredentrance, robust = "HC1")
# robust_sensitive_item_controls_rrponly_secondaryandhigheredentrance <- summ(sensitive_item_controls_rrponly_secondaryandhigheredentrance, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_secondaryandhigheredentrance_df <- broom::tidy(robust_sensitive_item_controls_fullsample_secondaryandhigheredentrance) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_secondaryandhigheredentrance_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_secondaryandhigheredentrance_df <- broom::tidy(robust_sensitive_item_controls_leftonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_secondaryandhigheredentrance_df)[7] <- "term"

robust_sensitive_item_controls_rightonly_secondaryandhigheredentrance_df <- broom::tidy(robust_sensitive_item_controls_rightonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_secondaryandhigheredentrance_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_secondaryandhigheredentrance_df <- broom::tidy(robust_sensitive_item_controls_rrponly_secondaryandhigheredentrance) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_secondaryandhigheredentrance_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_secondaryandhigheredentrance_df)[7] <- "term"


# Willingness to Sign Petition - secondaryandhigheredentrance only


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_secondaryandhigheredentrance <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_secondaryandhigheredentrance)
sign_petition_self_controls_leftonly_secondaryandhigheredentrance <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_secondaryandhigheredentrance)
sign_petition_self_controls_rightonly_secondaryandhigheredentrance <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_secondaryandhigheredentrance)
# sign_petition_self_controls_rrponly_secondaryandhigheredentrance <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_secondaryandhigheredentrance)

# robust SEs
robust_sign_petition_self_controls_fullsample_secondaryandhigheredentrance <- summ(sign_petition_self_controls_fullsample_secondaryandhigheredentrance, robust = "HC1")
robust_sign_petition_self_controls_leftonly_secondaryandhigheredentrance <- summ(sign_petition_self_controls_leftonly_secondaryandhigheredentrance, robust = "HC1")
robust_sign_petition_self_controls_rightonly_secondaryandhigheredentrance <- summ(sign_petition_self_controls_rightonly_secondaryandhigheredentrance, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_secondaryandhigheredentrance <- summ(sign_petition_self_controls_rrponly_secondaryandhigheredentrance, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_secondaryandhigheredentrance) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_secondaryandhigheredentrance_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_secondaryandhigheredentrance_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_secondaryandhigheredentrance_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_secondaryandhigheredentrance) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_secondaryandhigheredentrance_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_secondaryandhigheredentrance_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - secondaryandhigheredentrance only

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_secondaryandhigheredentrance)
petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_secondaryandhigheredentrance)
petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_secondaryandhigheredentrance)
# petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_secondaryandhigheredentrance)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance <- summ(petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance <- summ(petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance <- summ(petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance <- summ(petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance_df)[7] <- "term"



# Empirical Expectations - secondaryandhigheredentrance only

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_secondaryandhigheredentrance <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_secondaryandhigheredentrance)
sign_petition_others_controls_leftonly_secondaryandhigheredentrance <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_secondaryandhigheredentrance)
sign_petition_others_controls_rightonly_secondaryandhigheredentrance <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_secondaryandhigheredentrance)
# sign_petition_others_controls_rrponly_secondaryandhigheredentrance <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_secondaryandhigheredentrance)

# robust SEs
robust_sign_petition_others_controls_fullsample_secondaryandhigheredentrance <- summ(sign_petition_others_controls_fullsample_secondaryandhigheredentrance, robust = "HC1")
robust_sign_petition_others_controls_leftonly_secondaryandhigheredentrance <- summ(sign_petition_others_controls_leftonly_secondaryandhigheredentrance, robust = "HC1")
robust_sign_petition_others_controls_rightonly_secondaryandhigheredentrance <- summ(sign_petition_others_controls_rightonly_secondaryandhigheredentrance, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_secondaryandhigheredentrance <- summ(sign_petition_others_controls_rrponly_secondaryandhigheredentrance, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_secondaryandhigheredentrance) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_secondaryandhigheredentrance_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_secondaryandhigheredentrance_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_secondaryandhigheredentrance_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_secondaryandhigheredentrance_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_secondaryandhigheredentrance) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_secondaryandhigheredentrance_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_secondaryandhigheredentrance_df)[7] <- "term"



# Normative Expectations - secondaryandhigheredentrance only

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_secondaryandhigheredentrance)
petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_secondaryandhigheredentrance)
petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_secondaryandhigheredentrance)
# petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_secondaryandhigheredentrance)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance <- summ(petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance <- summ(petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance <- summ(petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance <- summ(petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance_df)[7] <- "term"



# Sanctioning - secondaryandhigheredentrance only

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_secondaryandhigheredentrance <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_secondaryandhigheredentrance)
delete_tweet_controls_leftonly_secondaryandhigheredentrance <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_secondaryandhigheredentrance)
delete_tweet_controls_rightonly_secondaryandhigheredentrance <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_secondaryandhigheredentrance)
# delete_tweet_controls_rrponly_secondaryandhigheredentrance <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_secondaryandhigheredentrance)

# robust SEs
robust_delete_tweet_controls_fullsample_secondaryandhigheredentrance <- summ(delete_tweet_controls_fullsample_secondaryandhigheredentrance, robust = "HC1")
robust_delete_tweet_controls_leftonly_secondaryandhigheredentrance <- summ(delete_tweet_controls_leftonly_secondaryandhigheredentrance, robust = "HC1")
robust_delete_tweet_controls_rightonly_secondaryandhigheredentrance <- summ(delete_tweet_controls_rightonly_secondaryandhigheredentrance, robust = "HC1")
# robust_delete_tweet_controls_rrponly_secondaryandhigheredentrance <- summ(delete_tweet_controls_rrponly_secondaryandhigheredentrance, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_secondaryandhigheredentrance_df <- broom::tidy(robust_delete_tweet_controls_fullsample_secondaryandhigheredentrance) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_secondaryandhigheredentrance_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_secondaryandhigheredentrance_df <- broom::tidy(robust_delete_tweet_controls_leftonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_secondaryandhigheredentrance_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_secondaryandhigheredentrance_df <- broom::tidy(robust_delete_tweet_controls_rightonly_secondaryandhigheredentrance) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_secondaryandhigheredentrance_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_secondaryandhigheredentrance_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_secondaryandhigheredentrance_df <- broom::tidy(robust_delete_tweet_controls_rrponly_secondaryandhigheredentrance) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_secondaryandhigheredentrance_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_secondaryandhigheredentrance_df)[7] <- "term"

# final joining of all the models
joined_models_controls_secondaryandhigheredentrance <- rbind(
  robust_sign_petition_self_controls_fullsample_secondaryandhigheredentrance_df,
  robust_sign_petition_self_controls_leftonly_secondaryandhigheredentrance_df,
  robust_sign_petition_self_controls_rightonly_secondaryandhigheredentrance_df,
  # robust_sign_petition_self_controls_rrponly_secondaryandhigheredentrance_df,
  robust_sensitive_item_controls_fullsample_secondaryandhigheredentrance_df,
  robust_sensitive_item_controls_leftonly_secondaryandhigheredentrance_df,
  robust_sensitive_item_controls_rightonly_secondaryandhigheredentrance_df,
  # robust_sensitive_item_controls_rrponly_secondaryandhigheredentrance_df,
  robust_petition_appropriate_self_controls_fullsample_secondaryandhigheredentrance_df,
  robust_petition_appropriate_self_controls_leftonly_secondaryandhigheredentrance_df,
  robust_petition_appropriate_self_controls_rightonly_secondaryandhigheredentrance_df,
  # robust_petition_appropriate_self_controls_rrponly_secondaryandhigheredentrance_df,
  robust_sign_petition_others_controls_fullsample_secondaryandhigheredentrance_df,
  robust_sign_petition_others_controls_leftonly_secondaryandhigheredentrance_df,
  robust_sign_petition_others_controls_rightonly_secondaryandhigheredentrance_df,
  # robust_sign_petition_others_controls_rrponly_secondaryandhigheredentrance_df,
  robust_petition_appropriate_others_controls_fullsample_secondaryandhigheredentrance_df,
  robust_petition_appropriate_others_controls_leftonly_secondaryandhigheredentrance_df,
  robust_petition_appropriate_others_controls_rightonly_secondaryandhigheredentrance_df,
  # robust_petition_appropriate_others_controls_rrponly_secondaryandhigheredentrance_df,
  robust_delete_tweet_controls_fullsample_secondaryandhigheredentrance_df,
  robust_delete_tweet_controls_leftonly_secondaryandhigheredentrance_df,
  robust_delete_tweet_controls_rightonly_secondaryandhigheredentrance_df
  # robust_delete_tweet_controls_rrponly_secondaryandhigheredentrance_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_secondaryandhigheredentrance$sample <- factor(joined_models_controls_secondaryandhigheredentrance$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e10 <- dwplot(joined_models_controls_secondaryandhigheredentrance,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "Secondary School and Higher Ed Entrance Exam: Treatment Conditions against Control Condition (With Controls)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e10.png", plot = fig_e10,
  width = 15, height = 10
)

# cleaning - University Graduates

# subset analysis data
analysis_data_unigrads <- analysis_data %>%
  filter(education == "Fachhochschulabschluss" | education == "Hochschulabschluss")

# mainstream only
mainstream_only_unigrads <- analysis_data_unigrads %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only_unigrads <- analysis_data_unigrads %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only_unigrads <- analysis_data_unigrads %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only_unigrads <- analysis_data_unigrads %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data_unigrads[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data_unigrads[, c(18, 19, 20, 21, 22, 23)])
left_only_unigrads[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only_unigrads[, c(18, 19, 20, 21, 22, 23)])
right_only_unigrads[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only_unigrads[, c(18, 19, 20, 21, 22, 23)])
# rrp_only_unigrads[,c(18,19,20,21,22,23)]<-scale(rrp_only_unigrads[,c(18,19,20,21,22,23)])


# Sensitive Item -  University Graduates

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_unigrads <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigrads)
sensitive_item_controls_leftonly_unigrads <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigrads)
sensitive_item_controls_rightonly_unigrads <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigrads)
# sensitive_item_controls_rrponly_unigrads <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigrads)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_unigrads <- summ(sensitive_item_controls_fullsample_unigrads, robust = "HC1")
robust_sensitive_item_controls_leftonly_unigrads <- summ(sensitive_item_controls_leftonly_unigrads, robust = "HC1")
robust_sensitive_item_controls_rightonly_unigrads <- summ(sensitive_item_controls_rightonly_unigrads, robust = "HC1")
# robust_sensitive_item_controls_rrponly_unigrads <- summ(sensitive_item_controls_rrponly_unigrads, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_unigrads_df <- broom::tidy(robust_sensitive_item_controls_fullsample_unigrads) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_unigrads_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_unigrads_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_unigrads_df <- broom::tidy(robust_sensitive_item_controls_leftonly_unigrads) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_unigrads_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_unigrads_df)[7] <- "term"

robust_sensitive_item_controls_rightonly_unigrads_df <- broom::tidy(robust_sensitive_item_controls_rightonly_unigrads) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_unigrads_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_unigrads_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_unigrads_df <- broom::tidy(robust_sensitive_item_controls_rrponly_unigrads) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_unigrads_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_unigrads_df)[7] <- "term"


# Willingness to Sign Petition - unigrads only


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_unigrads <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigrads)
sign_petition_self_controls_leftonly_unigrads <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigrads)
sign_petition_self_controls_rightonly_unigrads <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigrads)
# sign_petition_self_controls_rrponly_unigrads <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigrads)

# robust SEs
robust_sign_petition_self_controls_fullsample_unigrads <- summ(sign_petition_self_controls_fullsample_unigrads, robust = "HC1")
robust_sign_petition_self_controls_leftonly_unigrads <- summ(sign_petition_self_controls_leftonly_unigrads, robust = "HC1")
robust_sign_petition_self_controls_rightonly_unigrads <- summ(sign_petition_self_controls_rightonly_unigrads, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_unigrads <- summ(sign_petition_self_controls_rrponly_unigrads, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_unigrads_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_unigrads) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_unigrads_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_unigrads_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_unigrads_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_unigrads) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_unigrads_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_unigrads_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_unigrads_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_unigrads) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_unigrads_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_unigrads_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_unigrads_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_unigrads) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_unigrads_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_unigrads_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - unigrads only

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_unigrads <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigrads)
petition_appropriate_self_controls_leftonly_unigrads <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigrads)
petition_appropriate_self_controls_rightonly_unigrads <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigrads)
# petition_appropriate_self_controls_rrponly_unigrads <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigrads)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_unigrads <- summ(petition_appropriate_self_controls_fullsample_unigrads, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_unigrads <- summ(petition_appropriate_self_controls_leftonly_unigrads, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_unigrads <- summ(petition_appropriate_self_controls_rightonly_unigrads, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_unigrads <- summ(petition_appropriate_self_controls_rrponly_unigrads, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_unigrads_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_unigrads) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_unigrads_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_unigrads_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_unigrads_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_unigrads) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_unigrads_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_unigrads_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_unigrads_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_unigrads) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_unigrads_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_unigrads_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_unigrads_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_unigrads) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_unigrads_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_unigrads_df)[7] <- "term"



# Empirical Expectations - unigrads only

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_unigrads <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigrads)
sign_petition_others_controls_leftonly_unigrads <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigrads)
sign_petition_others_controls_rightonly_unigrads <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigrads)
# sign_petition_others_controls_rrponly_unigrads <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigrads)

# robust SEs
robust_sign_petition_others_controls_fullsample_unigrads <- summ(sign_petition_others_controls_fullsample_unigrads, robust = "HC1")
robust_sign_petition_others_controls_leftonly_unigrads <- summ(sign_petition_others_controls_leftonly_unigrads, robust = "HC1")
robust_sign_petition_others_controls_rightonly_unigrads <- summ(sign_petition_others_controls_rightonly_unigrads, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_unigrads <- summ(sign_petition_others_controls_rrponly_unigrads, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_unigrads_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_unigrads) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_unigrads_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_unigrads_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_unigrads_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_unigrads) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_unigrads_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_unigrads_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_unigrads_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_unigrads) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_unigrads_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_unigrads_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_unigrads_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_unigrads) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_unigrads_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_unigrads_df)[7] <- "term"



# Normative Expectations - unigrads only

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_unigrads <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigrads)
petition_appropriate_others_controls_leftonly_unigrads <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigrads)
petition_appropriate_others_controls_rightonly_unigrads <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigrads)
# petition_appropriate_others_controls_rrponly_unigrads <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigrads)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_unigrads <- summ(petition_appropriate_others_controls_fullsample_unigrads, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_unigrads <- summ(petition_appropriate_others_controls_leftonly_unigrads, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_unigrads <- summ(petition_appropriate_others_controls_rightonly_unigrads, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_unigrads <- summ(petition_appropriate_others_controls_rrponly_unigrads, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_unigrads_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_unigrads) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_unigrads_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_unigrads_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_unigrads_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_unigrads) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_unigrads_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_unigrads_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_unigrads_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_unigrads) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_unigrads_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_unigrads_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_unigrads_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_unigrads) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_unigrads_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_unigrads_df)[7] <- "term"



# Sanctioning - unigrads only

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_unigrads <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigrads)
delete_tweet_controls_leftonly_unigrads <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigrads)
delete_tweet_controls_rightonly_unigrads <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigrads)
# delete_tweet_controls_rrponly_unigrads <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigrads)

# robust SEs
robust_delete_tweet_controls_fullsample_unigrads <- summ(delete_tweet_controls_fullsample_unigrads, robust = "HC1")
robust_delete_tweet_controls_leftonly_unigrads <- summ(delete_tweet_controls_leftonly_unigrads, robust = "HC1")
robust_delete_tweet_controls_rightonly_unigrads <- summ(delete_tweet_controls_rightonly_unigrads, robust = "HC1")
# robust_delete_tweet_controls_rrponly_unigrads <- summ(delete_tweet_controls_rrponly_unigrads, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_unigrads_df <- broom::tidy(robust_delete_tweet_controls_fullsample_unigrads) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_unigrads_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_unigrads_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_unigrads_df <- broom::tidy(robust_delete_tweet_controls_leftonly_unigrads) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_unigrads_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_unigrads_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_unigrads_df <- broom::tidy(robust_delete_tweet_controls_rightonly_unigrads) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_unigrads_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_unigrads_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_unigrads_df <- broom::tidy(robust_delete_tweet_controls_rrponly_unigrads) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_unigrads_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_unigrads_df)[7] <- "term"

# final joining of all the models
joined_models_controls_unigrads <- rbind(
  robust_sign_petition_self_controls_fullsample_unigrads_df,
  robust_sign_petition_self_controls_leftonly_unigrads_df,
  robust_sign_petition_self_controls_rightonly_unigrads_df,
  # robust_sign_petition_self_controls_rrponly_unigrads_df,
  robust_sensitive_item_controls_fullsample_unigrads_df,
  robust_sensitive_item_controls_leftonly_unigrads_df,
  robust_sensitive_item_controls_rightonly_unigrads_df,
  # robust_sensitive_item_controls_rrponly_unigrads_df,
  robust_petition_appropriate_self_controls_fullsample_unigrads_df,
  robust_petition_appropriate_self_controls_leftonly_unigrads_df,
  robust_petition_appropriate_self_controls_rightonly_unigrads_df,
  # robust_petition_appropriate_self_controls_rrponly_unigrads_df,
  robust_sign_petition_others_controls_fullsample_unigrads_df,
  robust_sign_petition_others_controls_leftonly_unigrads_df,
  robust_sign_petition_others_controls_rightonly_unigrads_df,
  # robust_sign_petition_others_controls_rrponly_unigrads_df,
  robust_petition_appropriate_others_controls_fullsample_unigrads_df,
  robust_petition_appropriate_others_controls_leftonly_unigrads_df,
  robust_petition_appropriate_others_controls_rightonly_unigrads_df,
  # robust_petition_appropriate_others_controls_rrponly_unigrads_df,
  robust_delete_tweet_controls_fullsample_unigrads_df,
  robust_delete_tweet_controls_leftonly_unigrads_df,
  robust_delete_tweet_controls_rightonly_unigrads_df
  # robust_delete_tweet_controls_rrponly_unigrads_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_unigrads$sample <- factor(joined_models_controls_unigrads$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e12 <- dwplot(joined_models_controls_unigrads,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "University Graduates: Treatment Conditions against Control Condition (With Controls)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e12.png", plot = fig_e12,
  width = 15, height = 10
)

# cleaning - University Graduates and Higher Education Entrance Exam

# subset analysis data
analysis_data_unigradsandhigherentranceexam <- analysis_data %>%
  filter(education == "Fachhochschulabschluss" | education == "Hochschulabschluss" | education == "Advanced technical college entrance qualification" | education == "Subject-related higher education entrance qualification")

# mainstream only
mainstream_only_unigradsandhigherentranceexam <- analysis_data_unigradsandhigherentranceexam %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "FDP")

# RRP only
# rrp_only_unigradsandhigherentranceexam <- analysis_data_unigradsandhigherentranceexam %>%
#   filter(party_voted_2021 == "AfD")

# right-wing only
right_only_unigradsandhigherentranceexam <- analysis_data_unigradsandhigherentranceexam %>%
  filter(party_voted_2021 == "CDU/CSU" | party_voted_2021 == "FDP" | party_voted_2021 == "AfD")

# left-wing only
left_only_unigradsandhigherentranceexam <- analysis_data_unigradsandhigherentranceexam %>%
  filter(party_voted_2021 == "SPD" | party_voted_2021 == "Green" | party_voted_2021 == "Die Linke")

# standardize by subtracting mean and dividing by SD
analysis_data_unigradsandhigherentranceexam[, c(18, 19, 20, 21, 22, 23)] <- scale(analysis_data_unigradsandhigherentranceexam[, c(18, 19, 20, 21, 22, 23)])
left_only_unigradsandhigherentranceexam[, c(18, 19, 20, 21, 22, 23)] <- scale(left_only_unigradsandhigherentranceexam[, c(18, 19, 20, 21, 22, 23)])
right_only_unigradsandhigherentranceexam[, c(18, 19, 20, 21, 22, 23)] <- scale(right_only_unigradsandhigherentranceexam[, c(18, 19, 20, 21, 22, 23)])
# rrp_only_unigradsandhigherentranceexam[,c(18,19,20,21,22,23)]<-scale(rrp_only_unigradsandhigherentranceexam[,c(18,19,20,21,22,23)])


# Sensitive Item -  University Graduates and Higher Ed Entrance

# regression for Agreement with Sensitive Item across different samples
sensitive_item_controls_fullsample_unigradsandhigherentranceexam <- lm(sensitive_item_agree ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigradsandhigherentranceexam)
sensitive_item_controls_leftonly_unigradsandhigherentranceexam <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigradsandhigherentranceexam)
sensitive_item_controls_rightonly_unigradsandhigherentranceexam <- lm(sensitive_item_agree ~ MRPapprovedummy * RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigradsandhigherentranceexam)
# sensitive_item_controls_rrponly_unigradsandhigherentranceexam <- lm(sensitive_item_agree ~ MRPapprovedummy *RRPapprovedummy+ MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigradsandhigherentranceexam)

# robust SEs - "HC1" for STATA
robust_sensitive_item_controls_fullsample_unigradsandhigherentranceexam <- summ(sensitive_item_controls_fullsample_unigradsandhigherentranceexam, robust = "HC1")
robust_sensitive_item_controls_leftonly_unigradsandhigherentranceexam <- summ(sensitive_item_controls_leftonly_unigradsandhigherentranceexam, robust = "HC1")
robust_sensitive_item_controls_rightonly_unigradsandhigherentranceexam <- summ(sensitive_item_controls_rightonly_unigradsandhigherentranceexam, robust = "HC1")
# robust_sensitive_item_controls_rrponly_unigradsandhigherentranceexam <- summ(sensitive_item_controls_rrponly_unigradsandhigherentranceexam, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sensitive_item_controls_fullsample_unigradsandhigherentranceexam_df <- broom::tidy(robust_sensitive_item_controls_fullsample_unigradsandhigherentranceexam) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_fullsample_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sensitive_item_controls_fullsample_unigradsandhigherentranceexam_df)[7] <- "term"

robust_sensitive_item_controls_leftonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sensitive_item_controls_leftonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_leftonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sensitive_item_controls_leftonly_unigradsandhigherentranceexam_df)[7] <- "term"

robust_sensitive_item_controls_rightonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sensitive_item_controls_rightonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Agreement with Sensitive Item") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sensitive_item_controls_rightonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sensitive_item_controls_rightonly_unigradsandhigherentranceexam_df)[7] <- "term"

# robust_sensitive_item_controls_rrponly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sensitive_item_controls_rrponly_unigradsandhigherentranceexam) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Agreement with Sensitive Item") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")  %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sensitive_item_controls_rrponly_unigradsandhigherentranceexam_df)[1] <- "model"
# names(robust_sensitive_item_controls_rrponly_unigradsandhigherentranceexam_df)[7] <- "term"


# Willingness to Sign Petition - unigradsandhigherentranceexam only


# regression for Willingness to Sign Petition across different samples
sign_petition_self_controls_fullsample_unigradsandhigherentranceexam <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigradsandhigherentranceexam)
sign_petition_self_controls_leftonly_unigradsandhigherentranceexam <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigradsandhigherentranceexam)
sign_petition_self_controls_rightonly_unigradsandhigherentranceexam <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigradsandhigherentranceexam)
# sign_petition_self_controls_rrponly_unigradsandhigherentranceexam <- lm(sign_petition_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigradsandhigherentranceexam)

# robust SEs
robust_sign_petition_self_controls_fullsample_unigradsandhigherentranceexam <- summ(sign_petition_self_controls_fullsample_unigradsandhigherentranceexam, robust = "HC1")
robust_sign_petition_self_controls_leftonly_unigradsandhigherentranceexam <- summ(sign_petition_self_controls_leftonly_unigradsandhigherentranceexam, robust = "HC1")
robust_sign_petition_self_controls_rightonly_unigradsandhigherentranceexam <- summ(sign_petition_self_controls_rightonly_unigradsandhigherentranceexam, robust = "HC1")
# robust_sign_petition_self_controls_rrponly_unigradsandhigherentranceexam <- summ(sign_petition_self_controls_rrponly_unigradsandhigherentranceexam, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_self_controls_fullsample_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_self_controls_fullsample_unigradsandhigherentranceexam) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_fullsample_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sign_petition_self_controls_fullsample_unigradsandhigherentranceexam_df)[7] <- "term"

robust_sign_petition_self_controls_leftonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_self_controls_leftonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_leftonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sign_petition_self_controls_leftonly_unigradsandhigherentranceexam_df)[7] <- "term"


robust_sign_petition_self_controls_rightonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_self_controls_rightonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Willingness to Sign Petition") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_self_controls_rightonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sign_petition_self_controls_rightonly_unigradsandhigherentranceexam_df)[7] <- "term"

# robust_sign_petition_self_controls_rrponly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_self_controls_rrponly_unigradsandhigherentranceexam) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Willingness to Sign Petition") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_self_controls_rrponly_unigradsandhigherentranceexam_df)[1] <- "model"
# names(robust_sign_petition_self_controls_rrponly_unigradsandhigherentranceexam_df)[7] <- "term"


# Personal Views about Appropriateness of Signing Petition - unigradsandhigherentranceexam only

# regression for Personal Views about Appropriateness of Signing Petition across different samples
petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigradsandhigherentranceexam)
petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigradsandhigherentranceexam)
petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigradsandhigherentranceexam)
# petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam <- lm(petition_appropriate_self ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigradsandhigherentranceexam)

# robust SEs
robust_petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam <- summ(petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam, robust = "HC1")
robust_petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam <- summ(petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam, robust = "HC1")
robust_petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam <- summ(petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam, robust = "HC1")
# robust_petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam <- summ(petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam_df)[7] <- "term"

robust_petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam_df)[7] <- "term"


robust_petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Personal Views of Appropriateness of Signing") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam_df)[7] <- "term"

# robust_petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Personal Views of Appropriateness of Signing") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam_df)[1] <- "model"
# names(robust_petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam_df)[7] <- "term"



# Empirical Expectations - unigradsandhigherentranceexam only

# regression for Empirical Expectations across different samples
sign_petition_others_controls_fullsample_unigradsandhigherentranceexam <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigradsandhigherentranceexam)
sign_petition_others_controls_leftonly_unigradsandhigherentranceexam <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigradsandhigherentranceexam)
sign_petition_others_controls_rightonly_unigradsandhigherentranceexam <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigradsandhigherentranceexam)
# sign_petition_others_controls_rrponly_unigradsandhigherentranceexam <- lm(sign_petition_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigradsandhigherentranceexam)

# robust SEs
robust_sign_petition_others_controls_fullsample_unigradsandhigherentranceexam <- summ(sign_petition_others_controls_fullsample_unigradsandhigherentranceexam, robust = "HC1")
robust_sign_petition_others_controls_leftonly_unigradsandhigherentranceexam <- summ(sign_petition_others_controls_leftonly_unigradsandhigherentranceexam, robust = "HC1")
robust_sign_petition_others_controls_rightonly_unigradsandhigherentranceexam <- summ(sign_petition_others_controls_rightonly_unigradsandhigherentranceexam, robust = "HC1")
# robust_sign_petition_others_controls_rrponly_unigradsandhigherentranceexam <- summ(sign_petition_others_controls_rrponly_unigradsandhigherentranceexam, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_sign_petition_others_controls_fullsample_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_others_controls_fullsample_unigradsandhigherentranceexam) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_fullsample_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sign_petition_others_controls_fullsample_unigradsandhigherentranceexam_df)[7] <- "term"


robust_sign_petition_others_controls_leftonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_others_controls_leftonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_leftonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sign_petition_others_controls_leftonly_unigradsandhigherentranceexam_df)[7] <- "term"


robust_sign_petition_others_controls_rightonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_others_controls_rightonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Empirical Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_sign_petition_others_controls_rightonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_sign_petition_others_controls_rightonly_unigradsandhigherentranceexam_df)[7] <- "term"


# robust_sign_petition_others_controls_rrponly_unigradsandhigherentranceexam_df <- broom::tidy(robust_sign_petition_others_controls_rrponly_unigradsandhigherentranceexam) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Empirical Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_sign_petition_others_controls_rrponly_unigradsandhigherentranceexam_df)[1] <- "model"
# names(robust_sign_petition_others_controls_rrponly_unigradsandhigherentranceexam_df)[7] <- "term"



# Normative Expectations - unigradsandhigherentranceexam only

# regression for Normative Expectations across different samples
petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigradsandhigherentranceexam)
petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigradsandhigherentranceexam)
petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigradsandhigherentranceexam)
# petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam <- lm(petition_appropriate_others ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigradsandhigherentranceexam)

# robust SEs
robust_petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam <- summ(petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam, robust = "HC1")
robust_petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam <- summ(petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam, robust = "HC1")
robust_petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam <- summ(petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam, robust = "HC1")
# robust_petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam <- summ(petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam_df)[7] <- "term"

robust_petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam_df)[7] <- "term"

robust_petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Normative Expectations") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam_df)[7] <- "term"

# robust_petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam_df <- broom::tidy(robust_petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Normative Expectations") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right")%>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam_df)[1] <- "model"
# names(robust_petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam_df)[7] <- "term"



# Sanctioning - unigradsandhigherentranceexam only

# regression for Sanctioning across different samples
delete_tweet_controls_fullsample_unigradsandhigherentranceexam <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = analysis_data_unigradsandhigherentranceexam)
delete_tweet_controls_leftonly_unigradsandhigherentranceexam <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = left_only_unigradsandhigherentranceexam)
delete_tweet_controls_rightonly_unigradsandhigherentranceexam <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy + age + household_income + left_right, data = right_only_unigradsandhigherentranceexam)
# delete_tweet_controls_rrponly_unigradsandhigherentranceexam <- lm(delete_tweet ~ MRPapprovedummy + RRPapprovedummy + MRPdisapproveRRPapprovedummy + MRPapproveRRPapprovedummy +  age + household_income + left_right, data = rrp_only_unigradsandhigherentranceexam)

# robust SEs
robust_delete_tweet_controls_fullsample_unigradsandhigherentranceexam <- summ(delete_tweet_controls_fullsample_unigradsandhigherentranceexam, robust = "HC1")
robust_delete_tweet_controls_leftonly_unigradsandhigherentranceexam <- summ(delete_tweet_controls_leftonly_unigradsandhigherentranceexam, robust = "HC1")
robust_delete_tweet_controls_rightonly_unigradsandhigherentranceexam <- summ(delete_tweet_controls_rightonly_unigradsandhigherentranceexam, robust = "HC1")
# robust_delete_tweet_controls_rrponly_unigradsandhigherentranceexam <- summ(delete_tweet_controls_rrponly_unigradsandhigherentranceexam, robust = "HC1")

# convert regression outcomes to df for coefficient plot
robust_delete_tweet_controls_fullsample_unigradsandhigherentranceexam_df <- broom::tidy(robust_delete_tweet_controls_fullsample_unigradsandhigherentranceexam) %>%
  mutate(sample = "Full Sample") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_fullsample_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_delete_tweet_controls_fullsample_unigradsandhigherentranceexam_df)[7] <- "term"

robust_delete_tweet_controls_leftonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_delete_tweet_controls_leftonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Left Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_leftonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_delete_tweet_controls_leftonly_unigradsandhigherentranceexam_df)[7] <- "term"


robust_delete_tweet_controls_rightonly_unigradsandhigherentranceexam_df <- broom::tidy(robust_delete_tweet_controls_rightonly_unigradsandhigherentranceexam) %>%
  mutate(sample = "Right Wing Only") %>%
  mutate(measure = "Sanctioning") %>%
  filter(term != "age") %>%
  filter(term != "household_income") %>%
  filter(term != "education") %>%
  filter(term != "left_right") %>%
  filter(term != "(Intercept)")

# rename for the dwplot
names(robust_delete_tweet_controls_rightonly_unigradsandhigherentranceexam_df)[1] <- "model"
names(robust_delete_tweet_controls_rightonly_unigradsandhigherentranceexam_df)[7] <- "term"

# robust_delete_tweet_controls_rrponly_unigradsandhigherentranceexam_df <- broom::tidy(robust_delete_tweet_controls_rrponly_unigradsandhigherentranceexam) %>%
#   mutate(sample = "Radical Right Only") %>%
#   mutate(measure = "Sanctioning") %>%
#   filter(term != "age") %>%
#   filter(term != "household_income")  %>%
#   filter(term != "education")  %>%
#   filter(term != "left_right") %>%
#   filter(term != "(Intercept)")
#
# #rename for the dwplot
# names(robust_delete_tweet_controls_rrponly_unigradsandhigherentranceexam_df)[1] <- "model"
# names(robust_delete_tweet_controls_rrponly_unigradsandhigherentranceexam_df)[7] <- "term"

# final joining of all the models
joined_models_controls_unigradsandhigherentranceexam <- rbind(
  robust_sign_petition_self_controls_fullsample_unigradsandhigherentranceexam_df,
  robust_sign_petition_self_controls_leftonly_unigradsandhigherentranceexam_df,
  robust_sign_petition_self_controls_rightonly_unigradsandhigherentranceexam_df,
  # robust_sign_petition_self_controls_rrponly_unigradsandhigherentranceexam_df,
  robust_sensitive_item_controls_fullsample_unigradsandhigherentranceexam_df,
  robust_sensitive_item_controls_leftonly_unigradsandhigherentranceexam_df,
  robust_sensitive_item_controls_rightonly_unigradsandhigherentranceexam_df,
  # robust_sensitive_item_controls_rrponly_unigradsandhigherentranceexam_df,
  robust_petition_appropriate_self_controls_fullsample_unigradsandhigherentranceexam_df,
  robust_petition_appropriate_self_controls_leftonly_unigradsandhigherentranceexam_df,
  robust_petition_appropriate_self_controls_rightonly_unigradsandhigherentranceexam_df,
  # robust_petition_appropriate_self_controls_rrponly_unigradsandhigherentranceexam_df,
  robust_sign_petition_others_controls_fullsample_unigradsandhigherentranceexam_df,
  robust_sign_petition_others_controls_leftonly_unigradsandhigherentranceexam_df,
  robust_sign_petition_others_controls_rightonly_unigradsandhigherentranceexam_df,
  # robust_sign_petition_others_controls_rrponly_unigradsandhigherentranceexam_df,
  robust_petition_appropriate_others_controls_fullsample_unigradsandhigherentranceexam_df,
  robust_petition_appropriate_others_controls_leftonly_unigradsandhigherentranceexam_df,
  robust_petition_appropriate_others_controls_rightonly_unigradsandhigherentranceexam_df,
  # robust_petition_appropriate_others_controls_rrponly_unigradsandhigherentranceexam_df,
  robust_delete_tweet_controls_fullsample_unigradsandhigherentranceexam_df,
  robust_delete_tweet_controls_leftonly_unigradsandhigherentranceexam_df,
  robust_delete_tweet_controls_rightonly_unigradsandhigherentranceexam_df
  # robust_delete_tweet_controls_rrponly_unigradsandhigherentranceexam_df
)


# reorder to specify sequence in facet_wrap
joined_models_controls_unigradsandhigherentranceexam$sample <- factor(joined_models_controls_unigradsandhigherentranceexam$sample, # Reordering group factor levels
  levels = c("Full Sample", "Right Wing Only", "Left Wing Only", "Radical Right Only")
)

# final dwplot code
fig_e11 <- dwplot(joined_models_controls_unigradsandhigherentranceexam,
  vline = geom_vline(
    xintercept = 0,
    colour = "grey60",
    linetype = 2
  ),
  dot_args = list(aes(shape = model)),
  whisker_args = list(aes(linetype = model))
) +
  facet_wrap(~sample, nrow = 1) +
  theme(strip.text = element_text(size = 5)) +
  scale_colour_grey(
    start = .1,
    end = .1,
    # if start and end same value, use same colour for all models
    labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")
  ) +
  labs(title = "University Graduates and Higher Education Entrance Exam Qualifications: Treatment Conditions against Control Condition (With Controls)") +
  scale_shape_discrete(labels = c("MRP Approve and RRP Approve vs Control", "MRP Disapprove and RRP Approve vs Control", "RRP Approve vs Control", "MRP Approve vs Control")) +
  theme_bw() +
  theme(legend.position = "bottom") +
  theme(legend.text = element_text(size = rel(0.9))) +
  guides(
    shape = guide_legend("Treatment Condition", reverse = TRUE),
    colour = guide_legend("Treatment Condition", reverse = TRUE)
  ) + # Combine the legends for shape and color
  scale_y_discrete(labels = label_wrap(13))

ggsave(
  filename = "plots/fig_e11.png", plot = fig_e11,
  width = 15, height = 10
)
